<script>
  const endpoint = 'https://jsonplaceholder.typicode.com/users'

  // AbortController 示例
  const controller = new AbortController()

  const options = { signal: controller.signal }

  setTimeout(() => {
    console.log('Aborting fetch request after 1 second...')
    controller.abort() // 取消请求
  }, 1000)

  const fetchUsers = async () => {
    try {
      const response = await fetch(endpoint, options)
      if (!response.ok) throw new Error('Network response was not ok')
      await new Promise(resolve => {
        console.log('Waiting for 2 seconds...')
        return setTimeout(resolve, 2000) // 模拟延迟
      })
      const data = await response.json()
      console.log(data)
    } catch (error) {
      if (error.name === 'AbortError') {
        console.error('用户操作：Fetch request was aborted:', error)
      } else {
        console.error('用户操作：Fetch error:', error)
      }
      return
    }
  }

  fetchUsers()
</script>
